package featuresdemo;

import java.util.Date;

class SimpleClone implements Cloneable{
	Date birthdate;
	String name;
	public SimpleClone (String name, long seconds){
		this.birthdate = new Date(seconds);
		this.name = name;
	}
	public String toString(){
		return "name is: " + this.name + ", birthday is: " + this.birthdate.toString();
	}
	
	//clone shallow
	public SimpleClone clone() throws CloneNotSupportedException{
		return (SimpleClone) super.clone();
	}
}

public class SimpleCloneTest {
	public static void main(String[] args)
		throws CloneNotSupportedException{
		SimpleClone sc1 = new SimpleClone("Allen", 1000100000000L);
		System.out.println(sc1.toString());
		
		SimpleClone sc2 = sc1.clone();
		//成了两个独立对象，不过引用类型的field都指向同一个引用
		System.out.println("两个对象指向同一个地址吗？" + (sc1 == sc2));
		System.out.println("两个对象的name值(String)指向同一个地址吗？" + (sc1.name == sc2.name));
		System.out.println("两个对象的birthdate(Date)指向同一个地址吗？" + (sc1.birthdate == sc2.birthdate));

		//equals由equals方法指定
		System.out.println("两个对象equals？ " + (sc1.equals(sc2)));
		System.out.println("两个对象的name值(String)equals？ " + (sc1.name.equals(sc2.name)));
		System.out.println("两个对象的birthdate(Date)equals？" + (sc1.birthdate.equals(sc2.birthdate)));
	}

}
